package 剑指offer.Month7_07.day18;

import java.util.ArrayList;

public class 把二叉树打印成多行 {
    ArrayList<ArrayList<Integer>> lists = new ArrayList<>();
    int treeHeight = 0;
    ArrayList<ArrayList<Integer>> Print(TreeNode pRoot) {
        if(pRoot == null) return lists;
        solve(pRoot,0);
        return lists;
    }

    public void solve(TreeNode root,int height){
        if(height >= treeHeight){
            lists.add(new ArrayList<>());
            treeHeight++;
        }
        lists.get(height).add(root.val);
        if(root.left != null) solve(root.left,height + 1);
        if(root.right != null) solve(root.right,height + 1);
    }
}
